package com.jzfai.service;

import com.jzfai.entity.Access;
import com.jzfai.mapper.AccessMapper;
import com.jzfai.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Title: AccessService
 * @Description:
 * @Auther:kuanghua
 * @Version: 1.0
 * @create 2019/8/16 17:32
 */
@Service
public class AccessService {
    @Autowired
    AccessMapper AccessMapper;
    
    public JsonData addAccess(Access access){
        int i = AccessMapper.insertAccess(access);
        if(i>0){
            return  JsonData.buildSuccess();
        }else{
            return JsonData.buildError("添加权限失败");
        }
    }

    public JsonData editAccess(Access access){
        int i = AccessMapper.updateAccess(access);
        if(i>0){
            return  JsonData.buildSuccess();
        }else{
            return JsonData.buildError("更新权限失败");
        }
    }

    public JsonData deleteAccess(Integer id){
        int i = AccessMapper.deleteByIdAccess(id);
        if(i>0){
            return  JsonData.buildSuccess();
        }else{
            return JsonData.buildError("删除权限失败");
        }
    }

    public JsonData getListAccess(Access access){
        List<Access> listAccess = AccessMapper.selectListAccess(access);
        HashMap<String , Object> HashMap = new HashMap<>();
        HashMap.put("list",listAccess);
        return  JsonData.buildSuccess(HashMap);
    }
    
}
